package com.lion.tag.button;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import com.lion.tag.LionInputTag;
import com.lion.tag.util.AppendUtil;

public class Linkbutton extends LionInputTag {
	private String href;
	private String icon;
	private String text;
	private String plain;
	private String disabled = "false";
	private String toggle = "false";

	/**
	 * 实现A按钮
	 */
	@Override
	public void doTag() throws JspException, IOException {
		JspWriter out = getJspContext().getOut();
		StringBuilder sb = new StringBuilder(60);
		sb.append("<a ");
		sb = AppendUtil.addAttribute(sb, "id", id);
		if (href.indexOf("javascript") != -1 || href.indexOf("#") != -1 || !href.startsWith("http")) {
			sb = AppendUtil.addAttribute(sb, "href", href);
		} else {
			sb = AppendUtil.addAttribute(sb, "href", getContextPath() + href);
		}
		sb = AppendUtil.addAttribute(sb, "class", "easyui-linkbutton");
		sb = AppendUtil.addAttribute(sb, "onclick", onclick);
		sb = AppendUtil.addAttribute(sb, "style", style);
		sb = AppendUtil.addAttribute(sb, "plain", plain);
		int hasData = 0;
		hasData = AppendUtil.appendOptionData(sb, hasData, "iconCls", icon, true);
		if (disabled.equals("true")) {
			hasData = AppendUtil.appendOptionData(sb, hasData, "disabled", disabled, false);
		}
		if (toggle.equals("true")) {
			hasData = AppendUtil.appendOptionData(sb, hasData, "toggle", toggle, false);
		}
		if(hasData==1){
			sb.append("\">");
		}else{
			sb.append(">");
		}
		sb.append(text);
		sb.append("</a>");
		out.write(sb.toString());
	}

	/**
	 * @return the plain
	 */
	public String getPlain() {
		return plain;
	}

	/**
	 * @param plain
	 *            the plain to set
	 */
	public void setPlain(String plain) {
		this.plain = plain;
	}

	/**
	 * @return the id
	 */
	@Override
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	@Override
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the text
	 */
	public String getText() {
		return text;
	}

	/**
	 * @param text
	 *            the text to set
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * @return the href
	 */
	public String getHref() {
		return href;
	}

	/**
	 * @param href
	 *            the href to set
	 */
	public void setHref(String href) {
		this.href = href;
	}

	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	/**
	 * @param icon
	 *            the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	/**
	 * @return the disabled
	 */
	public String getDisabled() {
		return disabled;
	}

	/**
	 * @param disabled
	 *            the disabled to set
	 */
	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	/**
	 * @return the toggle
	 */
	public String getToggle() {
		return toggle;
	}

	/**
	 * @param toggle
	 *            the toggle to set
	 */
	public void setToggle(String toggle) {
		this.toggle = toggle;
	}

}
